@model List<Survey>
@using System.Security.Claims

@{
    ViewData["Title"] = "问卷列表";
}

<div class="container">
    @if (TempData["SuccessMessage"] != null)
    {
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            <i class="fas fa-check-circle me-2"></i>@TempData["SuccessMessage"]
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    }
    @if (TempData["ErrorMessage"] != null)
    {
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <i class="fas fa-exclamation-circle me-2"></i>@TempData["ErrorMessage"]
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    }
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2 class="mb-0">
            <i class="fas fa-clipboard-list text-primary me-2"></i>问卷列表
        </h2>
        @if (User.Identity?.IsAuthenticated == true)
        {
            <a asp-action="Create" class="btn btn-primary">
                <i class="fas fa-plus-circle me-1"></i>创建问卷
            </a>
        }
    </div>

    <div class="row mb-4">
        <div class="col-md-6">
            <div class="input-group">
                <span class="input-group-text bg-white border-end-0">
                    <i class="fas fa-search text-muted"></i>
                </span>
                <input type="text" class="form-control border-start-0" placeholder="搜索问卷..." id="searchInput">
                <button class="btn btn-outline-primary" type="button" id="searchButton">
                    搜索
                </button>
            </div>
        </div>
        <div class="col-md-6">
            <div class="btn-group float-end" role="group">
                <a href="@Url.Action("Index", new { filter = "all" })" class="btn btn-outline-primary @(ViewBag.CurrentFilter == "all" ? "active" : "")">
                    <i class="fas fa-list me-1"></i>全部
                </a>
                <a href="@Url.Action("Index", new { filter = "active" })" class="btn btn-outline-primary @(ViewBag.CurrentFilter == "active" ? "active" : "")">
                    <i class="fas fa-play-circle me-1"></i>进行中
                </a>
                <a href="@Url.Action("Index", new { filter = "ended" })" class="btn btn-outline-primary @(ViewBag.CurrentFilter == "ended" ? "active" : "")">
                    <i class="fas fa-stop-circle me-1"></i>已结束
                </a>
                <a href="@Url.Action("MySurveys")" class="btn btn-outline-primary @(ViewBag.CurrentFilter == "my" ? "active" : "")">
                    <i class="fas fa-user me-1"></i>我的问卷
                </a>
            </div>
        </div>
    </div>

    @if (!Model.Any())
    {
        <div class="text-center py-5">
            <i class="fas fa-clipboard-list fa-4x text-muted mb-3"></i>
            <h3 class="text-muted">暂无问卷</h3>
            <p class="text-muted">当前筛选条件下没有找到任何问卷</p>
            @if (ViewBag.CurrentFilter == "my")
            {
                <a asp-action="Create" class="btn btn-primary mt-3">
                    <i class="fas fa-plus-circle me-1"></i>创建我的第一个问卷
                </a>
            }
            else
            {
                <a asp-action="Create" class="btn btn-primary mt-3">
                    <i class="fas fa-plus-circle me-1"></i>创建问卷
                </a>
            }
        </div>
    }
    else
    {
        <div class="row g-4">
            @foreach (var survey in Model)
            {
                <div class="col-md-6 col-lg-4">
                    <div class="card h-100 shadow-sm hover-shadow">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-start mb-2">
                                <h5 class="card-title text-truncate mb-0" title="@survey.Title">@survey.Title</h5>
                                <span class="badge @(survey.IsActive ? "bg-success" : "bg-secondary")">
                                    @(survey.IsActive ? "进行中" : "已结束")
                                </span>
                            </div>
                            <p class="card-text text-muted small">
                                <i class="fas fa-user me-1"></i>@survey.Creator?.UserName
                            </p>
                            <p class="card-text text-muted small">
                                <i class="fas fa-calendar me-1"></i>@survey.CreatedAt.ToString("yyyy-MM-dd HH:mm")
                            </p>
                            <p class="card-text text-muted small">
                                <i class="fas fa-users me-1"></i>@survey.Responses.Count 个回答
                            </p>
                        </div>
                        <div class="card-footer bg-transparent border-top-0">
                            <div class="d-flex justify-content-between align-items-center">
                                <a asp-action="Details" asp-route-id="@survey.Id" class="btn btn-outline-primary btn-sm">
                                    <i class="fas fa-eye me-1"></i>查看
                                </a>
                                @if (User.Identity?.IsAuthenticated == true)
                                {
                                    <a asp-action="Fill" asp-route-id="@survey.Id" class="btn btn-primary btn-sm">
                                        <i class="fas fa-edit me-1"></i>填写
                                    </a>
                                }
                            </div>
                        </div>
                    </div>
                </div>
            }
        </div>
    }
</div>

@section Styles {
    <style>
        .survey-meta {
            font-size: 0.9rem;
            color: #6c757d;
        }
        .card {
            transition: all .3s ease;
            border: none;
            border-radius: 10px;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 .5rem 1rem rgba(0,0,0,.15)!important;
        }
        .btn-group .btn {
            border-radius: 0;
            padding: .5rem 1rem;
        }
        .btn-group .btn:first-child {
            border-top-left-radius: 0.25rem;
            border-bottom-left-radius: 0.25rem;
        }
        .btn-group .btn:last-child {
            border-top-right-radius: 0.25rem;
            border-bottom-right-radius: 0.25rem;
        }
        .input-group-text {
            border-radius: 0.25rem 0 0 0.25rem;
        }
        .form-control {
            border-radius: 0 0.25rem 0.25rem 0;
        }
        .badge {
            padding: 0.5em 0.75em;
            font-weight: 500;
        }
        .alert {
            border-radius: 10px;
            border: none;
            box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,.075);
        }
    </style>
}

@section Scripts {
    <script>
        $(document).ready(function() {
            // 搜索功能
            $('#searchButton').click(function() {
                var searchText = $('#searchInput').val().toLowerCase();
                $('.col-md-6').each(function() {
                    var title = $(this).find('.card-title').text().toLowerCase();
                    var description = $(this).find('.card-text').text().toLowerCase();
                    if (title.includes(searchText) || description.includes(searchText)) {
                        $(this).show();
                    } else {
                        $(this).hide();
                    }
                });
            });

            // 回车键触发搜索
            $('#searchInput').keypress(function(e) {
                if(e.which == 13) {
                    $('#searchButton').click();
                }
            });

            // 自动隐藏提示消息
            $('.alert').delay(4000).fadeOut(500);
        });
    </script>
} 